package io.github.tangwan.jdk8;

import java.util.Scanner;

/**
 * @author tangwan
 * @version V1.0
 * created on 2021/10/21 17:46
 * @since JDK 1.8
 */
public class ScaannnerTest {

    public static void main(String[] args) {
        int n = 0;
        long sheep = 0;
        n = utilInput();
        sheep = calcSheep(n);
        while (sheep <= 0) {
            n = utilInput();
            sheep = calcSheep(n);
        }
        System.out.println("第" + n + "年有" + sheep + "只吴丽阳~~");
    }

    public static int utilInput() {
        int n = 0;
        System.out.println("请输入第几年：（end结束）");
        Scanner sc = new Scanner(System.in);
        while (!sc.hasNext("end")) {
            if (sc.hasNextInt()) {
                n = sc.nextInt();
            } else {
                System.out.println("请输入整数：");
                String s = sc.next();
            }
        }
        sc.close();
        return n;
    }

    public static long calcSheep(int n) {
        int[] a = {1, 1, 2, 2, 4, 4, 7};
        if (n <= 7 && n > 0) {
            return a[n - 1];
        } else if (n <= 0) {
            System.out.println("年份应该大于0");
            return -1;
        } else {
            return calcSheep(n - 2) + calcSheep(n - 4);
        }
    }

}
